﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SmallSoft.Language.Presenter.Interface;
using SmallSoft.Language.Presenter;
using SmallSoft.Language.Presenter.Factory;
using SmallSoft.Language.View.Interface;

namespace SmallSoft.Language.View
{
    public class MainApp:ApplicationContext
    {
        private IFormNotifyView frmCardNotify;
        private bool isShow = false;

        private IMainAppPresenter presenter;
        public MainApp()
        {

            frmCardNotify = new FormNotify();
            presenter = MainAppPresenterFactory.GetMainViewPresenter();
            LoadDict();
            InitApp();
        }

        private void LoadDict()
        {
            if (presenter!=null)
            {
                presenter.GetDicts();
            }
        }

        private void InitApp()
        {
            Timer time = new Timer();
            time.Interval = 4000;
            time.Tick += new EventHandler(time_Tick);
            time.Start();
        }

        void time_Tick(object sender, EventArgs e)
        {
            isShow = !isShow;

            if (isShow)
            {
                frmCardNotify.SetModel(presenter.GetRandomWord());
                frmCardNotify.ShowNotify();
            }
            else
            {
                frmCardNotify.HideNotify();
            }
        }
    }
}
